package de.baumann.browser.activitys.duobao

import android.content.Context
import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import de.baumann.browser.OdinGlideModule
import de.baumann.browser.R
import de.baumann.browser.adapter.CodeListAdapter
import de.baumann.browser.base.BaseOdinActivity
import de.baumann.browser.iview.duobao.ICanYuDetailView
import de.baumann.browser.present.duobao.CanYuDetailPresenter
import de.baumann.browser.utils.StringUtil
import kotlinx.android.synthetic.main.activity_can_yu_detail.*
import kotlinx.android.synthetic.main.include_tool_bar_2.*

class CanYuDetailActivity : BaseOdinActivity<ICanYuDetailView, CanYuDetailPresenter>(), ICanYuDetailView {


    companion object {
        fun startCanYuDetailActivity(context: Context, id: String) {
            context.startActivity(Intent(context, CanYuDetailActivity::class.java).apply {
                putExtra("id", id)
            })
        }
    }

    private lateinit var codeListAdapter: CodeListAdapter

    override fun getLayout(): Int {
        return R.layout.activity_can_yu_detail
    }

    override fun getBackIcon(): Int {
        return R.drawable.ic_back
    }

    override fun getTitleText(): String {
        return "参与详情"
    }


    override fun initView() {
        initToolbar(commToolBar, commTitle)
        codeListAdapter = CodeListAdapter()
        cyhm.adapter = codeListAdapter
    }

    override fun initData() {
        presenter?.data()
    }

    override fun createPresenter(): CanYuDetailPresenter {
        return CanYuDetailPresenter()
    }

    override fun createView(): ICanYuDetailView {
        return this
    }

    override val id: String
        get() = intent.getStringExtra("id")

    override fun settx(tx: String) {
        OdinGlideModule.loadWithCropAndCircle(mContext, tx, itx, R.drawable.icon_head)
    }

    override fun setnc(nc: String) {
        tnc.text = nc
    }

    override fun setaddress(address: String) {
        cydz.text = StringUtil.StrReplace(address)
    }

    override fun settime(time: String) {
        cysj.text = time
    }

    override fun setqh(qh: String) {
        qihao.text = "${qh}期"
    }

    override fun setfs(fs: String) {
        cyfs.text = "参与${fs}份"
    }

    override fun sethm(list: List<String>) {
        codeListAdapter.setNewData(list)
    }
}